﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
using System.Transactions;
using System.Data.Entity.Infrastructure;

namespace IMC.Prepare.Data.Initializers
{
    public class CreateTablesIfNotExist<TContext> : IDatabaseInitializer<TContext> where TContext : DbContext
    {
        private readonly string[] _tablesToValidate;
        private readonly string[] _customCommands;

        public CreateTablesIfNotExist()//(string[] tablesToValidate, string[] customCommands)
            : base()
        {
            //this._tablesToValidate = tablesToValidate;
            //this._customCommands = customCommands;
        }
        public void InitializeDatabase(TContext context)
        {
            //bool dbExists;
            //using (new TransactionScope(TransactionScopeOption.Suppress))
            //{
            //    dbExists = context.Database.Exists();
            //}
            //if (dbExists)
            //{
            //    //create all tables
            //    var dbCreationScript = ((IObjectContextAdapter)context).ObjectContext.CreateDatabaseScript();
            //    context.Database.ExecuteSqlCommand(dbCreationScript);

            //    //Seed(context);
            //    context.SaveChanges();

            //    if (_customCommands != null && _customCommands.Length > 0)
            //    {
            //        foreach (var command in _customCommands)
            //            context.Database.ExecuteSqlCommand(command);
            //    }
            //}
            //else
            //{
            //    throw new ApplicationException("No database instance");
            //}
        }

    }
}
